<style>
.label {
  display: inline-block;
  margin: 10px 10px 0 0;
}
</style>
<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <span class="label">订单号</span>
      <el-form-item>
        <el-input v-model="orderNo" placeholder="订单号" clearable></el-input>
      </el-form-item>
     
       <el-form-item label="退税状态">
               <el-select v-model="statusId" placeholder="请选择" clearable>
                <el-option
                  v-for="item in statusList"
                  :key="item.value"
                  :value="item.value"
                  :label="item.name">
                </el-option>
              </el-select>
            </el-form-item>

      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
         <el-button type="primary" @click="exportList()">导出execl</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;"
    >
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="nickname" header-align="center" align="center" label="客户名称"></el-table-column>
      <el-table-column prop="orderNo" header-align="center" align="center" label="订单号"></el-table-column>
      <el-table-column prop="transferType" header-align="center" align="center" label="退税方式">
        <template slot-scope="scope">
          <div v-if="scope.row.transferType == '1'">银行卡</div>
          <div v-if="scope.row.transferType == '2'">支付宝</div>
          <div v-if="scope.row.transferType == '3'">微信</div>
        </template>
      </el-table-column>
      <el-table-column prop="taxPrice" header-align="center" align="center" label="退税金额"></el-table-column>
      <el-table-column prop="taxPoint" header-align="center" align="center" label="税点"></el-table-column>
      <el-table-column prop="accountNo" header-align="center" align="center" label="账号"></el-table-column>
      <el-table-column prop="bankName" header-align="center" align="center" label="开户行"></el-table-column>
      <el-table-column prop="realName" header-align="center" align="center" label="姓名"></el-table-column>
      <el-table-column prop="phone" header-align="center" align="center" label="电话"></el-table-column>
      <el-table-column prop="status" header-align="center" align="center" label="退税状态">
        <template slot-scope="scope">
          <div v-if="scope.row.status == '0'">未提交</div>
          <div v-if="scope.row.status == '1'">已提交</div>
          <div v-if="scope.row.status == '2'">已审核</div>
          <div v-if="scope.row.status == '3'">已转账</div>
          <div v-if="scope.row.status == '4'">审核终止</div>
          <div v-if="scope.row.status == '5'">审核未通过</div>
        </template>
      </el-table-column>
      <el-table-column prop="createdAt" header-align="center" align="center" label="创建时间"></el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" width="250" label="操作">
        <!-- <template slot-scope="scope">
          <a v-if="scope.row.flag == 0" :href="'#/biz-orderdetail?orderNo='+scope.row.orderNo+'&state='+scope.row.state">审核</a>
        </template>-->
        <template slot-scope="scope">
          <el-button
            type="text"
            v-if="scope.row.status == 1"
            size="small"
            @click="jumpToCheckPage(scope.row.id)"
          >审核</el-button>
          <el-button
            type="text"
            v-if="scope.row.status == 2"
            size="small"
            @click="returnAccount(scope.row.id,1)"
          >取消审核</el-button>
          <el-button
            type="text"
            v-if="scope.row.status == 2"
            size="small"
            @click="returnAccount(scope.row.id,3)"
          >确认转账</el-button>
          <el-button
            type="text"
            v-if="scope.row.status == 3"
            size="small"
            @click="returnAccount(scope.row.id,2)"
          >取消转账</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
import AddOrUpdate from "./drawbackRecord-add-or-update";
export default {
  data() {
    return {
      dataForm: {
        key: ""
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      statusId: '',
      dataListSelections: [],
      statusList: [{
            "value":0,
            "name":"未提交"
        },{
            "value":1,
            "name":"已提交"
        },{
            "value":2,
            "name":"已审核"
        },{
            "value":3,
            "name":"已转账"
        },{
            "value":4,
            "name":"审核终止"
        },{
            "value":5,
            "name":"审核未通过"
        }],
      addOrUpdateVisible: false
    };
  },
  components: {
    AddOrUpdate
  },
  activated() {
    this.getDataList();
  },
  methods: {
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("/biz/drawbackRecord/list"),
        method: "get",
        params: this.$http.adornParams({
          page: this.pageIndex,
          limit: this.pageSize,
          orderNo: this.orderNo,
          statusId: this.statusId
        })
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list;
          this.totalPage = data.page.totalCount;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 导出
    exportList() {
      this.$http({
        url: this.$http.adornUrl("/biz/drawbackRecord/export"),
        method: "get",
        params: this.$http.adornParams({
          page: this.pageIndex,
          limit: this.pageSize,
          orderNo: this.orderNo,
          statusId: this.statusId
        }),responseType: 'arraybuffer'
      }).then(({ data }) => {
       var blob = new Blob([data], {type: 'application/vnd.ms-excel;charset=utf-8'})
          var downloadElement = document.createElement('a');
          var href = window.URL.createObjectURL(blob); //创建下载的链接
          downloadElement.href = href;
          downloadElement.download = `退税申请记录.xlsx`; //下载后文件名
          document.body.appendChild(downloadElement);
          downloadElement.click(); //点击下载
          document.body.removeChild(downloadElement); //下载完成移除元素
          window.URL.revokeObjectURL(href); //释放掉blob对象
          // 
      });
    },
    
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val;
    },
    // 新增 / 修改
    jumpToCheckPage(id) {
      let query = { id: id };
      this.$router.push({
        name: "drawbackRecordCheck",
        query: query
      });
    },

    returnAccount(id, status) {
      this.$confirm(`确定退税转账已成功?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl(`/biz/drawbackRecord/updateStatus`),
          method: "post",
          data: this.$http.adornData({
            id: id,
            status: status
          })
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.$message({
              message: "操作成功",
              type: "success",
              duration: 1500,
              onClose: () => {
                this.getDataList();
              }
            });
          } else {
            this.$message.error(data.msg);
          }
        });
      });
    }
  }
};
</script>
